package com.zjt.videoplayer.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.zjt.itemvideoplayer.ItemVideoPlayerController;
import com.zjt.videoplayer.bean.Video;

import java.util.List;

public class VideoPlayerListAdapter extends RecyclerView.Adapter<VideoPlayerItemHolder> {

    private Context mContext;
    private List<Video> mVideoList;

    public VideoPlayerListAdapter(Context mContext, List<Video> videoList) {
        this.mVideoList = videoList;
        this.mContext = mContext;
    }

    @Override
    public VideoPlayerItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        VideoPlayerItemHolder holder = new VideoPlayerItemHolder(LayoutInflater.from(mContext), parent);
        holder.setController(new ItemVideoPlayerController(mContext));
        return holder;
    }

    @Override
    public void onBindViewHolder(VideoPlayerItemHolder holder, final int position) {
        Video video = mVideoList.get(position);
        holder.getController().setTitle(video.getTitle());
        holder.getController().setImage(video.getImageUrl());
        holder.getVideoPlayer().setController(holder.getController());
        holder.getVideoPlayer().setUp(video.getVideoUrl(), null);
    }

    @Override
    public int getItemCount() {
        return mVideoList.size();
    }
}
